﻿import com.gamepackage.events.Executable;

class com.gamepackage.events.Batch implements Executable
{
	private var list: Array;

	function Batch()
	{
		list = new Array();

		if ( arguments.length > 0 )
		{
			var e: Number;
			var exe: Executable;
			for( e in arguments )
			{
				exe = arguments[e];
				list.push( exe );
			}
		}
	}

	function push( exe: Executable ): Void
	{
		list.push( exe );
	}

	function remove( exe: Executable ): Boolean
	{
		var e: Number = list.length;
		
		while( --e > -1 )
		{
			if ( list[e] == exe )
			{
				list.splice( e , 1 );
				return true;
			}
		}
		return false;
	}

	function execute(): Void
	{
		var e: Number = list.length;

		if ( arguments.length == 0 )
		{
			while( --e > -1 )
			{
				list[e].execute();
			}
		}
		else
		{
			while( --e > -1 )
			{
				list[e].execute( arguments );
			}
		}
	}
}